#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

#define MAX_LEN 64
#define IO_R_BLOCK 1
#define IO_R_NONBLOCK 0

int mode = IO_R_BLOCK;

int main(int argc, char **argv)
{
	int fd;
	int len;
	char buf_r[MAX_LEN + 1];
	char buf_w[MAX_LEN + 1] = "hello world";

	//open
	if (mode == IO_R_BLOCK)
		fd = open("/dev/hello_dev", O_RDWR);  // block
	else
		fd = open("/dev/hello_dev", O_RDONLY | O_NONBLOCK);  // nonblock

	if(fd < 0) {
		perror("open error \n");
		return 0;
	}
	printf("open success \n");

	sleep(5);

	//read
	len = read(fd, buf_r, MAX_LEN);
	buf_r[len] = '\0';
	printf("read: %s, size: %d \n", buf_r, len);

	//close
	close(fd);
	printf("close() \n");

	return 0;
}
